package com.caocaog.market.controller;

import com.caocaog.market.entity.GoodsSpec;
import com.caocaog.market.service.GoodsSpecService;
import com.caocaog.market.vo.GoodsAttributeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.GenericController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 商品规格
 *
 * @author chechen
 * @date 2022-04-18
 */
@RestController
@Api(value = "goodsSpec", tags = "商品规格")
@RequestMapping("/goods/goodsSpecifications")
public class GoodsSpecController extends GenericController<GoodsSpec, GoodsSpecService> {

    /**
     * 通过商品id查询商品规格信息vo
     *
     * @param goodsId 商品id
     * @return 商品规格vo
     */
    @ApiOperation(value = "商品信息-通过id查询获取商品规格", notes = "商品信息-通过id查询获取商品规格")
    @GetMapping(value = "/getGoodsSpecificationsDataByGoodsId/{goodsId}")
    public Result<List<GoodsAttributeVo>> getGoodsSpecificationsDataByGoodsId(@PathVariable String goodsId) {
        List<GoodsAttributeVo> goodsSpecificationsVoList = super.service.getGoodsSpecDataByGoodsId(goodsId);
        if (goodsSpecificationsVoList.isEmpty())
            return Result.OK("该商品暂无规格", goodsSpecificationsVoList);
        return Result.OK(goodsSpecificationsVoList);
    }

}
